/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"592A8B72-8A54-444E-9C58-C7DFF9CDB83A",variableType:4}
 */
var f_codigo_anterior = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"D27E4C40-DE94-4B53-85B2-2F41BCD1B108"}
 */
var f_cuit = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3AE66A6D-02DF-4AB9-A3E1-C346B8872B9F",variableType:4}
 */
var f_hubo_cliente = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"0D143ABC-ACBB-4FEA-B68F-C3811DD7370F"}
 */
var f_razon_social = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"9888B827-90C7-42D9-B57D-FC517B999FB1"}
 */
function onAction_f_codigo_anterior(event) 
{
	buscar();
	if(f_hubo_cliente==1)
		Ira_clientes_det();
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"62A55E46-E3F6-413B-BAA4-F9DEFCD695BE"}
 */
function todos(event) 
{
	f_codigo_anterior=null;
	f_razon_social=null;
	f_cuit=null;
	if(event.getElementName()=='todos') 
		buscar();
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6C7C1666-BEC2-4E49-8A39-7CA6B25505AE"}
 */
function iniciar(firstShow, event) 
{
	application.setNumpadEnterAsFocusNextEnabled(false);
	if (firstShow)
	{
		foundset.loadAllRecords();
		databaseManager.setAutoSave(true);
		buscar();
	}
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"8F135189-49F4-40EF-AC56-B7C82C58ECBB"}
 */
function onHide(event) {
	application.setNumpadEnterAsFocusNextEnabled(true);
	return true
}

/**
 * @properties={typeid:24,uuid:"B0D0C523-C96F-4EF5-B8F3-6120E6DED742"}
 * @AllowToRunInFind
 */
function buscar() 
{
	foundset.loadAllRecords();
	if(controller.find()==false)
	{
		globals.gMensaje='No encontró clientes (find)';
		globals.DIALOGS.showInfoDialog('Clientes',  globals.gMensaje,  "OK")  //  30/12/2013
		return ; 
	}


	if (f_codigo_anterior!=null)
		cliente_id=f_codigo_anterior;
		
	if (f_razon_social!=null)
		razon_social='#%' + f_razon_social + '%';

	if (f_cuit!=null)
		cuit=f_cuit;

	if (controller.search()==0)
	{
		f_hubo_cliente=0;
		globals.gMensaje='No encontró cliente en ese rango'
		globals.DIALOGS.showInfoDialog('Clientes',  globals.gMensaje,  "OK")  //  30/12/2013
		return;
	}
	else
		f_hubo_cliente=1;
		
	elements.boton_detalle.requestFocus();  // queda parado en el primero que encontró
}

/**
 * @properties={typeid:24,uuid:"1E4621A0-3F1C-4FA6-A65D-220194CFE6B0"}
 */
function Ira_clientes_det() 
{
	globals.mostrarForm("clientes_abm_v3");
}
